<?php
/**
 * Created by PhpStorm.
 * Script Name: Onmessage.php
 * Create: 2023/3/18 10:57
 * Description:
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\wap\controller;


use plugin\wechat\app\MpController;
use support\Request;

class Auth extends MpController
{
    public function __construct()
    {
        parent::__construct();
    }


    /**
     * 网页授权发起页面
     * @param Request $request
     * @return mixed|\support\Response
     * Author: fudaoji<fdj@kuryun.cn>
     */
    function authPage(Request $request){
        if (!empty(session(SESSION_MP_FOLLOW))) {
            $target_url = session('target_url', url('index/index') . '?'.$request->queryString());
            return redirect($target_url);
        }
        if(input('doauth', 0)){
            $auth_url = $request->mpApp->oauth->scopes(['snsapi_userinfo'])
                ->redirect($request->domain() . url('Onmessage/wxAuth') .'?'. $request->queryString());
            return redirect($auth_url);
        }
        return $this->show();
    }
}